using System;
using System.Collections.Generic;
using System.Text;

namespace Client
{
    public class AsyncTask
    {
        Task m_task = new Task(6);

        public AsyncTask() { }

        public void RunTask(int tempo)
        {
            Console.WriteLine("Inciar tarefa");
            
            if(tempo > 0)
                m_task.DuracaoTask = tempo;

            m_task.BeginDoTask(new AsyncCallback(TaskCompleted), m_task);
        }

        private void TaskCompleted(IAsyncResult ar)
        {
            Task lt = (Task)ar.AsyncState;
            Console.WriteLine("Task completed at: {0}", lt.EndDoTask(ar));
            Console.WriteLine("All done, hit Enter to exit app.");
        }
        #region IDisposable Members


        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                this.Dispose();
            }
        }

        #endregion

    }
}
